<?php
// This file is used to set tags for a page

// Headers are needed to force IE to not cache results.
header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
header('Pragma: no-cache'); //HTTP/1.0

require_once('../../../includes.php');

require_once('../view/tags.php');
require_once('../model/page.php');
require_once("../redirect.php");

$page_ident = intval( $_POST['tags_ident'] );
$tags = folio_clean($_POST['content'], array(',','-','_',';') );

// Replace ; with ,
$tags = str_replace(';',',',$tags);

// See if we have permission to edit the current page.
$page = folio_page::SelectWherePageIdent( $page_ident );
if ( $page == false )
    trigger_error( 'Invalid page ident ' . $page_ident . ' passed to tags_update.php', E_USER_ERROR);
    
if ( !$page->Permission('update') )
    trigger_error( 'You do not have permission to edit this page.', E_USER_ERROR);

// Load the response data that tells us what to do next.
$redirect = folio_redirect::parse( $_POST );
if( !$redirect )
    trigger_error('Redirect information not passed to page_update.php', E_USER_ERROR);

// Update db tags
folio_tags::Update( $page, $tags );

// Create an object for the redirect.
$t = new stdClass();
$t->tags = $tags;
$tags = $t;

// Perform the required redirect actions.
//      This can send a header var to go to a new page, echo values, ...
$redirect->PerformRedirectActions( $tags );

?>
